package lc.com.lcpicturebackend.enums;

import cn.hutool.core.util.ObjUtil;
import lombok.Getter;

@Getter
public enum SpaceRoleEnum {

    VIEWER("viewer", 0),
    EDITOR("editor", 1),
    ADMIN("admin", 2);
    private final String text;
    private final int value;


    /**
     * 根据 value 获取枚举
     *
     * @param text  枚举文本
     * @param value 枚举值
     */
    SpaceRoleEnum(String text, int value) {
        this.text = text;
        this.value = value;

    }

    /**
     * 根据 value 获取枚举
     */
    public static SpaceRoleEnum getEnumByValue(Integer value) {
        if (ObjUtil.isEmpty(value)) {
            return null;
        }
        for (SpaceRoleEnum spaceLevelEnum : SpaceRoleEnum.values()) {
            if (spaceLevelEnum.value == value) {
                return spaceLevelEnum;
            }
        }
        return null;
    }
}
